
package com.yjh.admin.controller.user;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yjh.admin.entity.user.SysMenu;
import com.yjh.admin.server.sys.SysMenuService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import util.R;


/**
 * 菜单权限表
 *
 * @author GuoBin
 * @date 2020-10-14 16:49:40
 */
@ApiOperation("菜单权限表")
@RestController
@AllArgsConstructor
@RequestMapping("/sysmenu")
public class SysMenuController {

  private final SysMenuService sysMenuService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param sysMenu 菜单权限表
   * @return
   */
  @ApiOperation("分页查询")
  @GetMapping("/page")
  public R getSysMenuPage(Page page, SysMenu sysMenu) {
    return  new R<>(sysMenuService.page(page,Wrappers.query(sysMenu)));
  }


  /**
   * id查询菜单权限表
   * @param menuId id
   * @return R
   */
  @ApiOperation("通过id查询菜单权限表")
  @GetMapping("/getById")
  public R getById(@RequestParam("menuId") Integer menuId){
    return new R<>(sysMenuService.getById(menuId));
  }

  /**
   * 新增菜单权限表
   * @param sysMenu 菜单权限表
   * @return R
   */
  @ApiOperation("新增菜单权限表")
  @PostMapping
  public R save(@RequestBody SysMenu sysMenu){
    return new R<>(sysMenuService.save(sysMenu));
  }

  /**
   * 修改菜单权限表
   * @param sysMenu 菜单权限表
   * @return R
   */
  @ApiOperation("修改菜单权限表")
  @PutMapping
  public R updateById(@RequestBody SysMenu sysMenu){
    return new R<>(sysMenuService.updateById(sysMenu));
  }

  /**
   * 通过id删除菜单权限表
   * @param menuId id
   * @return R
   */
  @ApiOperation("删除菜单权限表")
  @DeleteMapping("/removeById")
  public R removeById(@RequestParam("menuId") Integer menuId){
    return new R<>(sysMenuService.removeById(menuId));
  }

  /**
   * 查询全部
   * @param
   * @return R
   */
  @ApiOperation("查询全部")
  @GetMapping("/queryAll")
  public R queryAll(){
    return new R<>(sysMenuService.list());
  }

}
